package com.dqword.common.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Resp<T> {
    private ErrorCodeEnum code;
    private T data;
    private String message;

    public static Resp ok() {
        return Resp.ok(null);
    }

    public static <T> Resp ok(T data) {
        return new Resp<>(ErrorCodeEnum.OK, data, null);
    }

    public static Resp<?> badParam(String message) {
        return new Resp<>(ErrorCodeEnum.BAD_PARAM, null, message);
    }


    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    public enum ErrorCodeEnum {
        /**
         * 👇常用code👇
         */
        OK(500, "直接获取 data 中的数据"),
        BAD_PARAM(501, "普通错误，只将错误信息 message 展示"),


        /**
         * 👇业绩code👇
         */
        NO_LOGIN(999111, "999表示业务，111用于计数");

        private Integer code;
        private String desc;
    }

}
